﻿///DottedLine.as 该类为虚线类
//vesion 1.0
//author 夏天的树人
package org.summerTree.graphics
{
	import flash.geom.Point;
	import flash.display.Sprite;
	import flash.events.*;
	public class DottedLine extends Base 
	{

		private var startPoint:Point;
		private var endPoint:Point;
		public function DottedLine()
		{

		}
		override public function clone():*
		{
			return new DottedLine();
		}
		//创建虚线
		/*startPoint 开始点
		 *endPoint 结束点
		 *length 分的段数长度
		 *grap  虚线的间距
		 */
		public function CreatDottedLine(startPoint:Point,endPoint:Point,length:Number,grap:Number):void
		{
			this.startPoint=startPoint;
			this.endPoint=endPoint;
			this.graphics.lineStyle(1,color);
			var max:Number = Point.distance(startPoint,endPoint);
			var l:Number = 0;
			var p3:Point;
			var p4:Point;
			while (l<max)
			{
				p3 = Point.interpolate(endPoint,startPoint,l/max);
				l+=length;
				if (l>max)
				{
					l=max;
				}
				p4 = Point.interpolate(endPoint,startPoint,l/max);
				this.graphics.moveTo(p3.x,p3.y);
				this.graphics.lineTo(p4.x,p4.y);
				l+=grap;
			}
		}
		public function addNode(radius:Number=5,fillColor:uint=0x000000):void
		{
           var node:Sprite=new Sprite();
		   addChild(node);
		   node.graphics.lineStyle(1);
		   node.graphics.beginFill(fillColor);
		   node.graphics.drawCircle(0,0,radius);
		   node.graphics.endFill();
		   node.x=startPoint.x;
		   node.y=startPoint.y;
		   node.addEventListener(MouseEvent.MOUSE_DOWN,node_MouseDown);
		   
		   var node2:Sprite=new Sprite();
		   addChild(node2);
		   node2.graphics.lineStyle(1);
		   node2.graphics.beginFill(fillColor);
		   node2.graphics.drawCircle(0,0,radius);
		   node2.graphics.endFill();
		   node2.x=endPoint.x;
		   node2.y=endPoint.y;
		   node2.addEventListener(MouseEvent.MOUSE_DOWN,node2_MouseDown);
		   
		}
		
		private function  node_MouseDown(event:MouseEvent):void
		{
			
			
		}
		
		private function  node2_MouseDown(event:MouseEvent):void
		{
			
			
		}
				//
//		public function clear():void
//		{
//			 
//			this.graphics.clear();
//		}
	}
}